using System;
using L=Science.Physics.GeneralPhysics;

namespace Serway.Chapter14
{
	/// <summary>
	/// Example10: Torricelli's Law
	/// An enclosed tank containing a liquid of density \rho has 
	/// a hole in its side at a distance y_1 from the tank's bottom 
	/// (Fig.14.21). The hole is open to the atmosphere, and 
	/// its diameter is much smaller than the diameter of the tank. 
	/// The air above the liquid is maintained at a pressure P. 
	/// Determine the speed of the liquid as it leaves the hole 
	/// when the liquid's level is a distance h above the hole.
	/// v_1 = \sqrt{2(P-P_0)/\rho + 2gh}
	/// </summary>
	public class Example10
	{
		public Example10()
		{
		}
		private string result;
		public string Result
		{
			get{return result;}
		}
		public void Compute()
		{
			L.Density rho = new L.Density();
			rho.kgPERmCUBE = 1000.0;
			L.Fluid water = new L.Fluid(rho);

			L.Pressure P0 = new L.Pressure();
			P0.Pa = 1.013E5;
			L.Pressure P1 = new L.Pressure();
			P1.Pa = 1.2E5;

			L.Velocity v0 = new L.Velocity();
			v0.XVariableQ = true;
			L.Velocity v1 = new L.Velocity();

			L.Length y0 = new L.Length();
			y0.m = 1.0;
			L.Length y1 = new L.Length();
			y1.m = 10.0;
			
			water.SolveBernoulliEquation(v0,y0,P0,v1,y1,P1);
			result += Convert.ToString(v0.X)+"\r\n";
            result += Convert.ToString(Math.Sqrt(2.0*(P1.Pa-P0.Pa)/rho.kgPERmCUBE
				+ 2.0*L.Constant.AccelerationOfGravity*(y1.m-y0.m)));
		}
	}
}
